package lanqiao;

/**
 * @Project : ProgrammingExercises
 * @Package : LanQiao.PrepareForCompetition
 * @File : Q0222.java
 * @Author : WangRuoyu
 * @Date : 2023/3/17 15:28
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q0222 {
    static int n;
    static int[] h;
    static final int N = 1000010;
    static int[] tr = new int[N];
    static long[] unhappy;

    static int lowbit(int x) {
        return x & -x;
    }

    static void add(int x, int c) {
        for (int i = x; i < N; i += lowbit(i)) {
            tr[i] += c;
        }
    }

    static int query(int x) {
        int res = 0;
        for (int i = x; i > 0; i -= lowbit(i)) {
            res += tr[i];
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");

        n = Integer.parseInt(words[0]);
        h = new int[n + 1];
        unhappy = new long[n + 1];

        words = br.readLine().split(" ");
        for (int i = 1; i <= n; ++i) {
            h[i] = Integer.parseInt(words[i - 1]) + 1;
            unhappy[i] += query(N - 1) - query(h[i]);
            add(h[i], 1);
        }

        tr = new int[N];
        for (int i = n; i > 0; i--) {
            unhappy[i] += query(h[i] - 1);
            add(h[i], 1);
        }

        long res = 0;
        for (int i = 1; i <= n; ++i) {
            res += ((1 + unhappy[i]) * unhappy[i]) >> 1;
        }

        System.out.println(res);
    }
}